import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDLotteryDrop {
	/**id*/
	id,
	/**奖励序列--每个奖励最多配置64个奖励，可以内部循环重置*/
	type,
	/**序列*/
	index,
	/**掉落id数组*/
	dropSet,
	/**下一个序列*/
	nextIndex,

	/**枚举数量*/
	EnumCount
}



export class CDLotteryDrop{
	/**id*/
	public id: number;
	/**奖励序列--每个奖励最多配置64个奖励，可以内部循环重置*/
	public type: number;
	/**序列*/
	public index: number;
	/**掉落id数组*/
	public dropSet: number[];
	/**下一个序列*/
	public nextIndex: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDLotteryDrop.id: return this.id;
			case E_CDLotteryDrop.type: return this.type;
			case E_CDLotteryDrop.index: return this.index;
			case E_CDLotteryDrop.dropSet: return this.dropSet;
			case E_CDLotteryDrop.nextIndex: return this.nextIndex;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDLotteryDrop.id: this.id = v; break;
			case E_CDLotteryDrop.type: this.type = v; break;
			case E_CDLotteryDrop.index: this.index = v; break;
			case E_CDLotteryDrop.dropSet: this.dropSet = v; break;
			case E_CDLotteryDrop.nextIndex: this.nextIndex = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDLotteryDrop> = new HashMap<number, CDLotteryDrop>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDLotteryDrop[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDLotteryDrop();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].type = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].index = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].dropSet = [];
			const attrArray = list[i].dropSet;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].nextIndex = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDLotteryDrop{
		return this.datas ? this.datas.get(id) : null;
	}
}
